#ifndef _TRACKER_H
#define _TRACKER_H
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#include "Netdefs.h"

/* The number of frames to remember so we could find out that a car parked. 
 * Set to 150 cause: 30 frames a sec, 5 sec to remember => 150 frames.			*/
int const NUMBER_OF_POINTS=240;//250;

/* The radius of the circle that will be treated as "in the same spot" for parking recognition */
int const OFFSET_RADIUS=100;//100;

//#define CAM

#ifdef CAM
CvPoint const ENTRANCE_LEFT_UP   = cvPoint ( 10,100 );
CvPoint const ENTRANCE_RIGHT_DOWN   = cvPoint ( 50 ,40 );
#else
CvPoint const ENTRANCE_LEFT_UP   = cvPoint ( 60,220 );
CvPoint const ENTRANCE_RIGHT_DOWN   = cvPoint ( 90 ,160 );
//CvPoint const ENTRANCE_LEFT_UP   = cvPoint ( 0,330 );
//CvPoint const ENTRANCE_RIGHT_DOWN   = cvPoint ( 50 ,240 );
#endif

#ifdef CAM
CvPoint const EXIT_LEFT_UP   = cvPoint ( 10,100 );
CvPoint const EXIT_RIGHT_DOWN   = cvPoint ( 50 ,40 );
CvPoint const PARK_LEFT_UP   = cvPoint(50,50);
CvPoint const PARK_RIGHT_DOWN = cvPoint(60,30);
#else
CvPoint const PARK_LEFT_UP   = cvPoint(50,300);
CvPoint const PARK_RIGHT_DOWN = cvPoint(400,270);
//CvPoint const PARK_LEFT_UP   = cvPoint(50,220);
//CvPoint const PARK_RIGHT_DOWN = cvPoint(600,30);
//CvPoint const EXIT_LEFT_UP   = cvPoint ( 0,400 );
//CvPoint const EXIT_RIGHT_DOWN   = cvPoint ( 30 ,330 );
CvPoint const EXIT_LEFT_UP   = cvPoint ( 0,280 );
CvPoint const EXIT_RIGHT_DOWN   = cvPoint ( 30 ,240 );
#endif


int const Xenter = 10;//(ENTRANCE_LEFT_UP.x + ENTRANCE_RIGHT_DOWN.x)/2;
int const Yenter = (ENTRANCE_LEFT_UP.y + ENTRANCE_RIGHT_DOWN.y)/2;

class car{
public:
	int licensePlate;
	uchar blue,green,red ;
	int h , s ,v;
	bool first_time;
	CvPoint p;
	CvPoint PointArr[NUMBER_OF_POINTS];
	int IndexToPointArr;
	bool check_park;
	bool is_park;
	car() {
		IndexToPointArr=0;
		check_park = false;
		first_time = true;
		is_park = false;
	}
	bool operator==( const car &right ){
		return ((right.licensePlate==this->licensePlate));
	}  
};


CvPoint calculateCenter(IplImage* img,int *new_data , car  car_to_check);

int* ConvertFromRgbToHsv(IplImage* img);

bool startTrackingCar( CvCapture* capture);

bool carArrived( CvPoint center, int lp );

void  initParkinglot( void *dummy , SocketClient *sock);




#endif